package com.estar.assistsurvy.adapter;

import java.util.List;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.EsBankCardInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BankCardListviewAdapter extends BaseAdapter {

	private List<EsBankCardInfo> esBankCardInfoList;
	private LayoutInflater inflater;

	public BankCardListviewAdapter(List<EsBankCardInfo> esBankCardInfoList, Context context) {
		super();
		this.esBankCardInfoList = esBankCardInfoList;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return esBankCardInfoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return esBankCardInfoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.listview_bankcard, null);
			holder=new ViewHolder();
			holder.cardName=(TextView) convertView.findViewById(R.id.cardName);
			holder.cardNum=(TextView) convertView.findViewById(R.id.cardNum);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		EsBankCardInfo bankCard=esBankCardInfoList.get(position);
		holder.cardName.setText(bankCard.getBankTopclassName());
		String cardNumber=bankCard.getBankCardNumber();
		String cardNumberTemp=null;
		if(cardNumber.length()>4){
			cardNumberTemp=cardNumber.substring(cardNumber.length()-4,cardNumber.length());
		}else{
			cardNumberTemp=cardNumber;
		}
		holder.cardNum.setText("尾号"+cardNumberTemp);
		return convertView;
	}
	
	private class ViewHolder{
		private TextView cardName,cardNum;
	}

}
